﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace NFinal.Common.Plugin
{
    /// <summary>
    /// 字典帮助类
    /// </summary>
    public class DictionaryHelper
    {
        public static IDictionary<TKey, TModel> ToDictionary<TModel, TKey>(IEnumerable<TModel> models, Func<TModel, TKey> selectKey)
        {
            IDictionary<TKey, TModel> list = new SortedList<TKey, TModel>();
            foreach (var model in models)
            {
                TKey key = selectKey(model);
                list.TryAdd(key, model);
            }
            return list;
        }
    }
}
